package ControlLayer;

import ModelLayer.*;
import java.util.ArrayList;
//model layer package has to be imported
/**
 * Controller class for the DVD collection
 * 
 * @author (Group1:Georgi,Roland and Mindaugas) 
 * @version (2005.03.31)
 * @revised version English (Ab)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class DVDCtr
{
     private DVDCollection collection;

    /**
     * Constructor for objects of class DVDCtr
     */
    public DVDCtr()
    {
        collection = DVDCollection.getDVDCollection();   
    }
    
    /**
     * Searched through the DVD collection for a DVD using its ID and returns its title.
     */
    public String findDVDTitle( long id)
    {
       return collection.searchDVD(id).getTitle();
    }
    /**
     *  Searched through the DVD collection for a DVD using its ID and returns its Artist.
     */
    public String findDVDArstist(long id)
    {
        return collection.searchDVD(id).getArtist();
    }
    
    /**
     *  Searched through the DVD collection for a DVD using its ID and returns its Publication Date.
     */
    public String findDVDPublicationDate(long id)
    {
        return collection.searchDVD(id).getPublicationDate();
    }
    
    /**
     * Sends a command to the model layers DVD collection to Create a new DVD.
     */
    public void createDVD(long id, String title, String artist, String publicationDate)
    {       
        collection.createDVD(id, title, artist, publicationDate);
    }
    
    /**
     *Sends a command to the model layers DVD collection to Delete a DVD using its ID.
     */
    public void deleteDVD(long id)
    {    
       collection.deleteDVD(id);
    }
    
    /**
     * Sends a command to the model layers DVD collection to Create a new Copy.
     */
    public void createCopy(long id, long serialNumber, String purchaseDate, int purchasePrice)
    {
       collection.searchDVD(id).createCopy(serialNumber, purchaseDate, purchasePrice);    
    }
    
    /**
     * Sends a command to the model layers DVD collection to Delete a Copy using its serial number.
     */
     public void deleteCopy(long id, long serialNumber)
    {
        collection.searchDVD(id).deleteCopy(serialNumber);
    }
    
    /**
     * Updates the DVD's details
     */
    public void updateDVD(long id, String title, String artist, String publicationDate)
    {
        updateDVDTitle( id, title);
        updateDVDArtist(id, artist);
        updateDVDPublicationDate(id, publicationDate);
    }
    
    /**
     * Searches a DVD using its id through the model layers DVD Collection and calls its Mutator Methods.
     */
    public void updateDVDTitle(long id, String title)
    {
        collection.searchDVD(id).setTitle(title);
    }
    
    public void updateDVDArtist(long id, String artist)
    {
        collection.searchDVD(id).setArtist(artist);
    }
    
    public void updateDVDPublicationDate(long id, String publicationDate)
    {
        collection.searchDVD(id).setPublicationDate(publicationDate);
    }
    
    /**
     * Updates the Copies details.
     */
     public void updateCopy(long id, long serialNumber, String purchaseDate, int purchasePrice)
    {
        updateCopyPurchaseDate(id, serialNumber, purchaseDate);
        updateCopyPurchasePrice(id, serialNumber, purchasePrice);
    }
    /**
     * Searches the copy of a DVD and searches the DVD through the model layer DVD collection and calls its Mutator Methods.
     */
    public void updateCopyPurchaseDate(long id, long serialNumber, String purchaseDate)
    {
        collection.searchDVD(id).searchCopy(serialNumber).setPurchaseDate(purchaseDate);
    }
    
    public void updateCopyPurchasePrice(long id, long serialNumber, int purchasePrice)
    {
        collection.searchDVD(id).searchCopy(serialNumber).setPurchasePrice(purchasePrice);
    }
    
    /**
     * Sends a command to the model layers DVD collection and calls the Accesor methods that return information about all dvds.
     */
      public ArrayList<String> getAllTitles()
    {
          
          return collection.getAllTitles() ;
    }
    
    public ArrayList<String> getAllArtists()
    {
          
          return collection.getAllArtists() ;
    }
    
    public ArrayList<String> getPublicationDates()
    {
          return collection.getPublicationDates() ;
    }
    
    public ArrayList<Long> getAllIDs()
    {
          
          return collection.getAllIDs() ;
    }
    
    public String getDVDTitle(long id)
    {
        return collection.searchDVD(id).getTitle();
    }
    
    public String getDVDArtist(long id)
    {
        return collection.searchDVD(id).getArtist();
    }
    
    public String getDVDPublicationDate(long id)
    {
        return collection.searchDVD(id).getPublicationDate();
    }
    /**
     * Sends a command to the model layers DVD collection and calls the Accesor methods that return information about all copies.
     */
    public String getCopyPurchaseDate(long id, long serialNumber)
    {
        return collection.searchDVD(id).searchCopy(serialNumber).getPurchaseDate();
    }
    
    public int getCopyPurchasePrice(long id, long serialNumber)
    {
        return collection.searchDVD(id).searchCopy(serialNumber).getPurchasePrice();
    }
    /**
     * sends a command to the model layers DVD collection to check if a DVD exists.
     */
    public boolean dvdExist(long id)
    {
        return collection.dvdExist(id);
    }
    
    /**
     * sends a command to the model layers DVD collection to check if a Copy exists.
     */
    public boolean copyExist(long dvdID,long copyID)
    {
        return collection.copyExist(dvdID,copyID);
    }
}
